//两两交换链表中的节点
//测试链接：https://leetcode.cn/problems/swap-nodes-in-pairs/description/
public class SwapPairs {
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }

    }

    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null) return head;  //特殊情况
        ListNode temp = swapPairs(head.next.next);
        ListNode ans = head.next;
        head.next.next = head;
        head.next = temp;

        return ans;
    }
}
